package com.huike.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huike.entity.Admin;
import com.huike.entity.Information;
import com.huike.mapper.InformationMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huike.service.IInformationService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Lwen
 * @since 2019-11-12
 */
@Service
public class InformationServiceImpl extends ServiceImpl<InformationMapper, Information> implements IInformationService {

    @Override
    public IPage<Information> listByPage(Admin admin,int page, int limit) {
        QueryWrapper<Information> wrapper = new QueryWrapper<>();
        Page<Information> pages = new Page<>(page,limit);
        if(!admin.getGride().equals("超级管理员")){
            wrapper.eq("belong_user",admin.getUid());
        }
        wrapper.orderByDesc("time"); //增加时间逆序条件
        IPage<Information> iPage =  baseMapper.selectPage(pages,wrapper);
        return iPage;
    }

    @Override
    public IPage<Information> listByPage(int page, int limit) {
        QueryWrapper<Information> wrapper = new QueryWrapper<>();
        Page<Information> pages = new Page<>(page,limit);
        wrapper.orderByDesc("time"); //增加时间逆序条件
        IPage<Information> iPage =  baseMapper.selectPage(pages,wrapper);
        return iPage;
    }

    @Override
    public boolean insertInfomation(Admin admin, Information information) {
        information.setBelongUser(admin.getUid());
        int res = baseMapper.insert(information);
        if (res==1){
            return true;
        }
        return false;
    }

    @Override
    public Boolean deleteInformation(List<String> ids) {
        int res = baseMapper.deleteBatchIds(ids);
        if (res==1){
            return true;
        }
        return false;
    }
}
